package com.dao;

import com.entity.Student;
import com.excel.StudentExcel;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository("studentDao")
public interface StudentDao {

    @Insert({
            "<script>",
            "insert into student(number,identity,report_date,photograph,state,class_id) values",
            "<foreach collection=\"studentList\" item=\"student\" separator=\",\">",
            "(#{student.number},#{student.identity},#{student.reportDate},#{student.photograph},",
            "#{student.state},#{student.classId})",
            "</foreach>",
            "</script>"
    })
    int insertBatch(@Param("studentList") List<Student> studentList);

    @Select("select number from student")
    List<String> queryNumberAll();

    @Select("select count(*) from student")
    long count();

    @Select({
            "select s.sid,s.number,s.identity,s.report_date,s.photograph,s.state,g.g_name,m.m_name,c.c_name from ",
            "student s left join class_grade g on s.class_id=g.gid",
            " left join major m on g.m_id=m.mid left join college c on m.college_id=c.cid",
            " limit #{start},#{end}"
    })
    @Results({
            @Result(id = true, column = "sid", property = "id"),
            @Result(column = "number", property = "number"),
            @Result(column = "identity", property = "identity"),
            @Result(column = "report_date", property = "reportDate"),
            @Result(column = "photograph", property = "photograph"),
            @Result(column = "state", property = "state"),
            @Result(column = "g_name", property = "className"),
            @Result(column = "m_name", property = "majorName"),
            @Result(column = "c_name", property = "collegeName")
    })
    List<StudentExcel> queryAllLimit(int start, long end);

    @Select("select identity from student")
    List<String> queryIdentityAll();
}
